package com.marisfrolg.scanner.base;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

import com.lidroid.xutils.DbUtils;
import com.lidroid.xutils.exception.DbException;
import com.marisfrolg.scanner.entity.CodeMapper;

import android.app.Application;
import android.os.Environment;

public class BaseApplication extends Application {
	private Map<String, Object> gValue=new HashMap<String, Object>();

	@Override
	public void onCreate() {
		super.onCreate();
		File dir=new File(Environment.getExternalStorageDirectory().getPath()+"/code/");
		if(!dir.exists()){
			dir.mkdirs();
		}
		File dbFile=new File(Environment.getExternalStorageDirectory().getPath()+"/code/code.db");
		if(!dbFile.exists()){
			try {
				InputStream is= this.getAssets().open("code.db");
				OutputStream out=new FileOutputStream(dbFile);
			    byte buf[]=new byte[1024];
			    int len;
			    while((len=is.read(buf))>0)
			    out.write(buf,0,len);
			    out.close();
			    is.close();
			} catch (IOException e) {
				e.printStackTrace();
				dbFile.delete();
			}
		}
		
//		DbUtils.create(this, Environment.getExternalStorageDirectory().getPath()+"/code/", "code.db");
//		DbUtils db=DbUtils.create(this);
//		CodeMapper cm=new CodeMapper();
//		cm.setOldcode("6916999000713");
//		cm.setNewcode("查到新编码OOXX");
//		try {
//			db.saveBindingId(cm);
//		} catch (DbException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	}
	public Map<String, Object> getgValue() {
		return gValue;
	}

	public void setgValue(Map<String, Object> gValue) {
		this.gValue = gValue;
	}
}
